package edu;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

import edu.jiemian;

public class inquire extends JFrame {
    private static final long serialVersionUID = -1928970409928880648L;
    JLabel jlpno = new JLabel("工      号：");
    JLabel jlxiaoxue = new JLabel("小      学：");
    JLabel jlchuzhong = new JLabel("初      中：");
    JLabel jlgaozhong = new JLabel("高      中：");
    JLabel jldaxue = new JLabel("大      学：");
    JLabel jlshuoshi = new JLabel("硕      士：");
    JLabel jlboshi = new JLabel( "博      士：");
    JLabel jlxuewei = new JLabel("学      位：");

    JTextField jtpno = new JTextField("",20);

    JLabel jxiaoxue = new JLabel();
    JLabel jchuzhong = new JLabel();
    JLabel jgaozhong = new JLabel();
    JLabel jdaxue = new JLabel();
    JLabel jshuoshi = new JLabel();
    JLabel jboshi = new JLabel();
    JLabel jxuewei= new JLabel();

    JButton buttonask = new JButton("查询");
    JButton buttonreturn = new JButton("返回");

    public inquire() {
        JPanel jppno = new JPanel();
        JPanel jpxiaoxue = new JPanel();
        JPanel jpchuzhong = new JPanel();
        JPanel jpdaxue = new JPanel();
        JPanel jpgaozhong = new JPanel();
        JPanel jpshuoshi = new JPanel();
        JPanel jpboshi = new JPanel();
        JPanel jpxuewei = new JPanel();
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));

        jppno.add(jlpno);
        jppno.add(jtpno);

        jpxiaoxue.add(jlxiaoxue);
        jpxiaoxue.add(jxiaoxue);

        jpchuzhong.add(jlchuzhong);
        jpchuzhong.add(jchuzhong);

        jpdaxue.add(jlgaozhong);
        jpdaxue.add(jgaozhong);

        jpgaozhong.add(jldaxue);
        jpgaozhong.add(jdaxue);

        jpshuoshi.add(jlshuoshi);
        jpshuoshi.add(jshuoshi);

        jpboshi.add(jlboshi);
        jpboshi.add(jboshi);

        jpxuewei.add(jlxuewei);
        jpxuewei.add(jxuewei);


        jpforbutton.add(buttonask);
        jpforbutton.add(buttonreturn);
        buttonask.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String xpno = jtpno.getText();
                Connection conn = null;
                ResultSet res = null;
                Statement stat = null;
                String sql = "SELECT DISTINCT allstaff.pno,xxm,czm,gzm,dxm,ssm,bsm,xueli FROM xx,cz,gz,dx,ss,bs,allstaff WHERE allstaff.pno='"+xpno+"' AND xx.pno='"+xpno+"' AND cz.pno='"+xpno+"' AND gz.pno='"+xpno+"' AND dx.pno='"+xpno+"' AND ss.pno='"+xpno+"' AND bs.pno='"+xpno+"';";
                try{
                    Class.forName("com.mysql.cj.jdbc.Driver");
                    System.out.println("jdbc haha");
                }catch(Exception d){
                    System.out.println("jdbc fall");
                    d.printStackTrace();
                }
                try{
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/work", "root", "123456");
                    stat=conn.createStatement();
                    res=stat.executeQuery(sql);
                    while (res.next())
                    {
                        String i = res.getString(1).trim();
                        if (i.equals(jtpno.getText()))
                        {
                            jxiaoxue.setText(res.getString(2));
                            jchuzhong.setText(res.getString(3));
                            jdaxue.setText(res.getString(5));
                            jgaozhong.setText(res.getString(4));
                            jshuoshi.setText(res.getString(6));
                            jboshi.setText(res.getString(7));
                            jxuewei.setText(res.getString(8));
                            break;
                        }
                    }
                }catch (SQLException e1) {
                    e1.printStackTrace();


                }
                finally{
                    try{
                        conn.close();
                    }catch(SQLException ar){
                        ar.printStackTrace();
                    }

                }}}

        );
        buttonreturn.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                dispose();
            }
        });
        this.setTitle("查询员工学位");
        this.setLayout(new GridLayout(9,1));
        this.add(jppno);
        this.add(jpxiaoxue);
        this.add(jpchuzhong);
        this.add(jpdaxue);
        this.add(jpgaozhong);
        this.add(jpshuoshi);
        this.add(jpboshi);
        this.add(jpxuewei);
        this.add(jpforbutton);
        this.setLocation(400,300);
        this.setSize(350,300);
        this.setVisible(true);

    }
}

